package com.kgc.ljp.util;

import java.io.*;
import java.util.Map;

public class SetUtil {
    public static void writeObj(Map<?,?> map, String path){
        ObjectOutputStream oos = null;
        if (path!=null){
            try {
                oos = new ObjectOutputStream(new FileOutputStream(path));
                oos.writeObject(map);
            } catch (IOException e) {
                e.printStackTrace();
            }finally {
                try {
                    if (oos!=null){
                        oos.close();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    public static Object readObj(String path){
        Object object = null;
        File file = new File(path);
        ObjectInputStream ois = null;
        if (file.exists()){
            try {
                ois = new ObjectInputStream(new FileInputStream(file));
                object = ois.readObject();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } finally {
                try {
                    if (ois!=null){
                        ois.close();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return object;
    }
}
